﻿using Cl.Entity.DataBaseEntity.User;
using Cl.Repository;
using Cl.Service.ElsaWorkflow.Modes;
using Elsa.ActivityResults;
using Elsa.Attributes;
using Elsa.Design;
using Elsa.Metadata;
using Elsa.Services.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Cl.Service.ElsaWorkflow.Activity.ClNotification
{
    [Trigger(Category = "ClActivitys", DisplayName = "通知", Description = "发送通知")]
    public class NotificationActivity : Elsa.Services.Activity, IActivityPropertyOptionsProvider
    {
        #region UI
        [ActivityInput(
        UIHint = ActivityInputUIHints.Dropdown,
        OptionsProvider = typeof(NotificationActivity),
        Label = "通知目标")]
        public string NfType { get; set; }


        [ActivityInput(
        UIHint = ActivityInputUIHints.MultiText,
        DefaultSyntax = "Json",
        SupportedSyntaxes = new[] { "Json", "Liquid" },
        IsDesignerCritical = true,
        Label = "用户")]
        public List<string> Phone { get; set; }
        #endregion

        public object GetOptions(PropertyInfo property)
        {
            var rv = new List<ComboSelectListItem>();
            if (property.Name == "NfType")
            {
                rv.Add(new ComboSelectListItem { Text = "执行人", Value = "1" });
                rv.Add(new ComboSelectListItem { Text = "委托人", Value = "2" });
                rv.Add(new ComboSelectListItem { Text = "自定义", Value = "3" });
                return rv;
            }
            return rv;
        }

        private ClRepository<User> UserRepository => new ClRepository<User>();//Repository不能单例
        public NotificationActivity()
        {

        }

        protected override IActivityExecutionResult OnExecute(ActivityExecutionContext context)
        {
            switch (NfType)
            {
                case "1":

                    break;
                case "2":
                    break;
                case "3":
                    break;
                default:
                    break;
            }

            var a = UserRepository.AsQueryable().ToList();
            return Done();
        }

    }
}
